<template>
  <div>
    <!--header start-->
    <div class="nav-head">
      <div class="_title">天恒微服务工作流管理平台</div>
      <div class="_search"><input type="text" placeholder="请输入搜索关键字"/></div>
      <ul class="_system">
        <li v-if="systemArr && systemArr.length>0"
            v-for="item in systemArr"
            :class="{'active':item.isChecked}"
            @click="goModule(item)">
          <span>{{item.text}}</span>
        </li>
      </ul>
      <div class="_user" title="退出" @click="logOut"><img src="./assets/default-img.png" alt="img"><span>{{userInfo.userName}}</span></div>
      <div class="_msg"><img src="./assets/clock.png" alt="clock"><span></span></div>
    </div>
    <!--child system with iframe-->
    <iframe id="iframe" width="100%" scrolling="no" frameborder="no" :src="iframeSrc" ref="iframe"></iframe>
  </div>
</template>

<script>
  import {getCookie,delCookie} from './utils';
  import request from '@/utils/request';

  export default {
    name: "Home",
    data(){
      return {
        userInfo:{},
        systemArr:[
          /*{
            name:'基础管理平台',
            url:'http://127.0.0.1/rbac/login.html',
            isChecked:true,
          },
          {
            name:'工作流',
            url:'http://192.168.0.93:8099',
            isChecked:false,
          },
          {
            name:'图形报表',
            url:'http://localhost:8000/#/login',
            isChecked:false,
          },
          {
            name:'服务治理',
            url:'http://192.168.0.244:8848/nacos/#/configurationManagement?dataId=&group=&appName=&namespace=',
            isChecked:false,
          },
          {
            name:'运行维护',
            url:'http://192.168.0.249:3000',
            isChecked:false,
          },*/
        ],
        iframeSrc:'',
      }
    },
    mounted(){
      new Promise((resolve, reject) => {
        request('user/selectWorkFlowManageInfo',{})
          .then(response => {
            if (response.code && response.code == 200) {
              if (response.data) {
                if (response.data.hasOwnProperty('userDetails'))
                  this.userInfo = response.data.userDetails;
                if (response.data.hasOwnProperty('menuContainer') && Array.isArray(response.data.menuContainer.menuBarList)){
                  let navList = response.data.menuContainer.menuBarList;
                  navList.map((item,index)=>{
                    if(index===0)
                      item.isChecked=true; //默认选中第一个菜单
                    else
                      item.isChecked=false;
                  });
                  this.systemArr=navList;
                  this.iframeSrc=this.systemArr[0].url;
                }else{
                  alert('暂无数据');
                  delCookie('token');
                  this.$router.push("/");
                }
              }
            }
            resolve();
          })
          .catch(error => {
            reject(error);
          });
      });
    },
    methods:{
      goModule(data){
        this.iframeSrc=data.url;
        this.systemArr.map(item=>{
          item.isChecked=false;
        });
        data.isChecked=true;
      },
      logOut(){
        this.$router.replace('/');
      }
    }
  }
</script>

<style scoped>
  ::-moz-placeholder {
    color: #79a0ef;
  }

  :-ms-input-placeholder {
    color: #79a0ef;
  }

  ::-webkit-input-placeholder {
    color: #79a0ef;
  }
  .nav-head{
    width: 100%;
    height: 48px;
    line-height: 48px;
    background-color: #2955ae;
    display: flex;
    flex-direction: row;
    align-items: center;
    padding: 0 32px;
  }
  .nav-head ._title{
    color: #fff;
    font-size: 20px;
    background: url("./assets/logo.png") no-repeat left;
    background-size: 28px auto;
    padding-left: 40px;
  }
  .nav-head ._search{
    border: 1px solid #4a72cc;
    border-radius: 16px;
    margin-left: 48px;
    padding: 0 8px;
    display: inline;
    height: 32px;
    line-height: 32px;
  }
  .nav-head ._search input{
    background: transparent url("./assets/search.png") no-repeat left center;
    background-size: auto 18px;
    padding-left:24px;
    color: #fff;
    height: 100%;
    vertical-align: top;
  }
  .nav-head ul,.nav-head ul li {
    list-style:none;
  }
  .nav-head ul._system{
    flex: 1;
    display: inline-block;
    padding-left: 32px;
  }
  .nav-head ul:after{
    display: block;
    content: '';
    clear: both;
  }
  .nav-head ul._system li{
    float: left;
    padding: 0 24px;
    cursor: pointer;
    color: #79a0ef;
    font-size: 16px;
  }
  .nav-head ul li.active span{
    padding: 4px 0;
    color: #fff;
    border-bottom: 2px solid #fff;
  }
  .nav-head ._user{
    color: #fff;
    font-size: 16px;
    cursor: pointer;
  }
  .nav-head ._user img{
    vertical-align: middle;
    padding-right: 8px;
  }
  .nav-head ._user span{
    vertical-align: middle;
  }
  .nav-head ._msg{
    margin-left: 32px;
    position: relative;
  }
  .nav-head ._msg span{
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: #ee3a79;
    position: absolute;
    top: 12px;
    right: 0;
  }
  .nav-head ._msg img{
    vertical-align: middle;
  }
  iframe{
    height: calc(100% - 48px);
  }
</style>
